package ch.sv7.tool.dbmanager.integration.sybase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import junit.framework.TestCase;

import org.hsqldb.Types;

import ch.sv7.tool.dbmanager.Context;
import ch.sv7.tool.dbmanager.db.ColumnType;
import ch.sv7.tool.dbmanager.db.DatabaseSchema;
import ch.sv7.tool.dbmanager.db.dialect.CustomTypeConversion;
import ch.sv7.tool.dbmanager.db.dialect.Dialect;
import ch.sv7.tool.dbmanager.db.dialect.DialectFactory;
import ch.sv7.tool.dbmanager.db.difference.ColumnAutoIncrementDifference;
import ch.sv7.tool.dbmanager.db.difference.ColumnDefaultValueDifference;
import ch.sv7.tool.dbmanager.db.difference.ColumnSizeTooBigDifference;
import ch.sv7.tool.dbmanager.db.difference.ColumnSizeTooSmallDifference;
import ch.sv7.tool.dbmanager.db.difference.ColumnTypeDifference;
import ch.sv7.tool.dbmanager.db.difference.ExtraColumnDifference;
import ch.sv7.tool.dbmanager.db.difference.ExtraIndexDifference;
import ch.sv7.tool.dbmanager.db.difference.IndexNameDifference;
import ch.sv7.tool.dbmanager.db.difference.MissingColumnDifference;
import ch.sv7.tool.dbmanager.db.difference.MissingIndexDifference;
import ch.sv7.tool.dbmanager.db.difference.MissingTableDifference;
import ch.sv7.tool.dbmanager.db.difference.NotNullableColumnDifference;
import ch.sv7.tool.dbmanager.db.difference.NullableColumnDifference;
import ch.sv7.tool.dbmanager.db.difference.SchemaDifferences;
import ch.sv7.tool.dbmanager.db.difference.filter.NameExcludeDifferenceFilter;
import ch.sv7.tool.dbmanager.db.fix.SchemaFixes;
import ch.sv7.tool.dbmanager.db.sql.SQLDatabaseSchemaFactory;
import ch.sv7.tool.dbmanager.db.xml.XmlDatabaseSchemaFactory;
import ch.sv7.tool.dbmanager.types.TypesInfo;
import ch.sv7.tool.dbmanager.types.TypesInfoFactory;
import ch.sv7.tool.dbmanager.util.SQLHelper;
import ch.sv7.tool.log.Appender;
import ch.sv7.tool.log.DefaultAppender;
import ch.sv7.tool.log.Logger;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class SybaseTestCase extends TestCase {

	private Connection connection;
	private Dialect dialect;
	private TypesInfo typesInfo;
	private Context context;
	
	protected void setUp() throws Exception {
		super.setUp();
		Logger.setAppender(new DefaultAppender(Appender.LEVEL_INFO));
		connection = ConnectionFactory.getTestConnection();
		typesInfo = TypesInfoFactory.getInstance().getTypesInfo("sybase", connection);
		dialect = DialectFactory.getInstance().getDialect("sybase", typesInfo);
		context = new Context(dialect, null);
		
		try {
			connection.setAutoCommit(true);
			SQLHelper.executeSQL("drop table jdbc_manager_test_a", connection);
			SQLHelper.executeSQL("drop table jdbc_manager_test_b", connection);
			SQLHelper.executeSQL("drop table jdbc_manager_test_c", connection);
		} catch (Exception e) {
			// ignore
		}
	}
	
	public Dialect getDialect() {
		return dialect;
	}
	
	public Context getContext() {
		return context;
	}
	
	public TypesInfo getTypesInfo() {
		return typesInfo;
	}
	
	public Connection getConnection(){
		return connection;
	}
	
	protected void tearDown() throws Exception {
		getConnection().close();
		super.tearDown();
	}

	public void testConverters() throws Exception {
		CustomTypeConversion converter = getContext().getConverter("image", "unitext");
		assertNotNull(converter);
	}
	
	public boolean insertDefaultData(){
		return true;
	}
	/*
	 * 		Logger.setAppender(new DefaultAppender(Appender.LEVEL_DEBUG));
	 * 		diffs.dump(System.out);
	 */
	
	public void testMissingTable() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		assertEquals(MissingTableDifference.class, diffs.getDifference(0).getClass());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
	}
	public void testMissingColumn() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		SQLHelper.executeSQL("alter table jdbc_manager_test_a drop name_def", getConnection());
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(MissingColumnDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(insertDefaultData() ? 1 : 0, diffs.getSize());
		diffs.addFilter(new NameExcludeDifferenceFilter("NullableColumnDifference"));
		assertEquals(0, diffs.getSize());
	}
	
	public void testExtraNullableColumn() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		SQLHelper.executeSQL("alter table jdbc_manager_test_a add test int null", getConnection());
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ExtraColumnDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(insertDefaultData() ? 1 : 0, diffs.getSize());
		diffs.addFilter(new NameExcludeDifferenceFilter("ExtraColumnDifference"));
		assertEquals(0, diffs.getSize());
	}

	public void testExtraNonNullableColumn() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").removeColumnSchema("name_not_null");
		
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ExtraColumnDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(insertDefaultData() ? 1 : 0, diffs.getSize());
		diffs.addFilter(new NameExcludeDifferenceFilter("ExtraColumnDifference"));
		assertEquals(0, diffs.getSize());
	}
		
	public void testExtraNonNullableColumnWithDefault() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").removeColumnSchema("name_def");
		
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ExtraColumnDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(insertDefaultData() ? 1 : 0, diffs.getSize());
		diffs.addFilter(new NameExcludeDifferenceFilter("ExtraColumnDifference"));
		assertEquals(0, diffs.getSize());
	}
		
	
	
	public void testMissingIndex() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		SQLHelper.executeSQL("drop index jdbc_manager_test_a.idx1", getConnection());
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(MissingIndexDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());

	}

	public void testExtraIndex() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		SQLHelper.executeSQL("create index idx3 on jdbc_manager_test_a (name)", getConnection());
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ExtraIndexDifference.class, diffs.getDifference(0).getClass());
		assertEquals("idx3", ((ExtraIndexDifference)diffs.getDifference(0)).getIndex().getName());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
	}

	public void testIndexColumnOrder() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		SQLHelper.executeSQL("drop index jdbc_manager_test_a.idx2", getConnection());
		SQLHelper.executeSQL("create index idx2 on jdbc_manager_test_a (number, name)", getConnection());
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(2, diffs.getSize());
		assertEquals(MissingIndexDifference.class, diffs.getDifference(0).getClass());
		assertEquals(ExtraIndexDifference.class, diffs.getDifference(1).getClass());
		assertEquals("name, number", ((MissingIndexDifference)diffs.getDifference(0)).getIndex().getColumns());
		assertEquals("number, name", ((ExtraIndexDifference)diffs.getDifference(1)).getIndex().getColumns());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
	}
	
	
	public void testColumnSizeTooSmall() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		SQLHelper.executeSQL("alter table jdbc_manager_test_a modify name varchar(10) null", getConnection());
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnSizeTooSmallDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());

	}

	public void testColumnNotNullableWithDefault() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name_def").getType().setNullable(true);
		
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(NotNullableColumnDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());

		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name_def").getType().setNullable(false);
		
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(NullableColumnDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());

	}
	
	
	public void testColumnSizeTooLarge() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		SQLHelper.executeSQL("alter table jdbc_manager_test_a modify name varchar(50) null", getConnection());
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnSizeTooBigDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());

	}

	
	public void testColumnTypeImplicitChange() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
			
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setTypeName("date");
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setJDBCType(Types.DATE);
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setSize(ColumnType.NO_SIZE_PROVIDED);

		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnTypeDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());

	}	
	
	public void testColumnTypeExplicitChange() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null) values (1, 'test')", getConnection());			
		}
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setTypeName("decimal");
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setJDBCType(Types.INTEGER);
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setSize(10);

		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnTypeDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(insertDefaultData() ? 1 : 0, diffs.getSize());
		diffs.addFilter(new NameExcludeDifferenceFilter("ExtraColumnDifference"));
		assertEquals(0, diffs.getSize());

	}	

	public void testColumnAutoIncrement() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null, number) values (1, 'test', 1)", getConnection());			
		}	
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("number").getType().setAutoIncrement(true);
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("number").getType().setNullable(false);

		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnAutoIncrementDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(insertDefaultData() ? 1 : 0, diffs.getSize());
		diffs.addFilter(new NameExcludeDifferenceFilter("ExtraColumnDifference"));
		assertEquals(0, diffs.getSize());

	}		
	
	public void testColumnAddDefaultValue() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null, number) values (1, 'test', 1)", getConnection());			
		}	
		Logger.setAppender(new DefaultAppender(Appender.LEVEL_DEBUG));

		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setDefaultValue("'test'");
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnDefaultValueDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());

	}
	
	public void testColumnChangeDefaultValue() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		if (insertDefaultData()) {
			SQLHelper.executeSQL("insert into jdbc_manager_test_a (id, name_not_null, number) values (1, 'test', 1)", getConnection());			
		}	
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name_def").getType().setDefaultValue("'EMPTY2'");

		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnDefaultValueDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());

	}
	
	public void testColumnChangeDefaultValueData() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_unicode.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();

		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
			
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		diffs.addFilter(new NameExcludeDifferenceFilter("ColumnSizeTooBigDifference"));
		assertEquals(0, diffs.getSize());
		
		Data data1 = new Data();
		data1.id = 1;
		insertData(data1, getConnection());
		
		Data data2 = new Data();
		data2.id = 2;
		data2.name = "test";
		insertData(data2, getConnection());
		sqlSchema = sqlFactory.getDatabaseSchema();
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setDefaultValue("'EMPTY'");
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setNullable(false);

		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		diffs.addFilter(new NameExcludeDifferenceFilter("ColumnSizeTooBigDifference"));
		//assertEquals(1, diffs.getSize());
		//assertEquals(ColumnDefaultValueDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		diffs.addFilter(new NameExcludeDifferenceFilter("ColumnSizeTooBigDifference"));
		
	}
	

	
	public void testColumnTypeExplicitChangeAndIndexRenameNoData() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_test_1.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
			
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setTypeName("decimal");
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setJDBCType(Types.INTEGER);
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("name").getType().setSize(10);
		SQLHelper.executeSQL("sp_rename 'jdbc_manager_test_a.idx2', idx_test, 'index'", getConnection());

		sqlSchema = sqlFactory.getDatabaseSchema();
		
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(2, diffs.getSize());
		assertEquals(ColumnTypeDifference.class, diffs.getDifference(0).getClass());
		assertEquals(IndexNameDifference.class, diffs.getDifference(1).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		//diffs.addFilter(new NameExcludeDifferenceFilter("ExtraColumnDifference"));
		//assertEquals(0, diffs.getSize());

	}	

	public void testColumnTypeCustomChangeData() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_unicode.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
			
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		diffs.addFilter(new NameExcludeDifferenceFilter("ColumnSizeTooBigDifference"));
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("data").getType().setTypeName("unitext");
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("data").getType().setJDBCType(Types.CLOB);
		Data data1 = new Data();
		data1.id = 1;
		insertData(data1, getConnection());
		
		Data data2 = new Data();
		data2.id = 2;
		String complexString2 = new String("dfkjghsadlkfjgh");
		data2.data = complexString2.getBytes("UTF8");
		insertData(data2, getConnection());
		
		Data data3 = new Data();
		data3.id = 3;
		String complexString3 = new String("\u00F6");
		data3.data = complexString3.getBytes("UTF8");
		insertData(data3, getConnection());
		
		sqlSchema = sqlFactory.getDatabaseSchema();
		
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		diffs.addFilter(new NameExcludeDifferenceFilter("ColumnSizeTooBigDifference"));
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnTypeDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		diffs.addFilter(new NameExcludeDifferenceFilter("ColumnSizeTooBigDifference"));

		assertEquals(1, diffs.getSize());
		diffs.addFilter(new NameExcludeDifferenceFilter("ExtraColumnDifference"));
		assertEquals(0, diffs.getSize());
		
		verifyData(data1, null, getConnection());
		verifyData(data2, complexString2, getConnection());
		verifyData(data3, complexString3, getConnection());

	}	
	
	public void testIncompatibleColumnTypeChangeNoData() throws Exception {
		XmlDatabaseSchemaFactory factory = 
			new XmlDatabaseSchemaFactory(
					this.getClass().getResourceAsStream("/ch/sv7/tool/dbmanager/db/sybase/schema_unicode.xml"), null);
		DatabaseSchema xmlSchema = factory.getDatabaseSchema();
		SQLDatabaseSchemaFactory sqlFactory = new SQLDatabaseSchemaFactory(getConnection(), getDialect());
		DatabaseSchema sqlSchema = sqlFactory.getDatabaseSchema();
		
		SchemaDifferences diffs = new SchemaDifferences();
		
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		// one table is missing
		assertEquals(1, diffs.getSize());
		
		SchemaFixes fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
			
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		diffs.addFilter(new NameExcludeDifferenceFilter("ColumnSizeTooBigDifference"));
		assertEquals(0, diffs.getSize());
		
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("data").getType().setTypeName("varchar");
		xmlSchema.getTableSchema("jdbc_manager_test_a").getColumnSchema("data").getType().setJDBCType(Types.VARCHAR);
		
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		diffs.addFilter(new NameExcludeDifferenceFilter("ColumnSizeTooBigDifference"));
		assertEquals(1, diffs.getSize());
		assertEquals(ColumnTypeDifference.class, diffs.getDifference(0).getClass());
		fixes = new SchemaFixes(getDialect(), getContext(), diffs);
		fixes.apply(getConnection(), null);
		sqlSchema = sqlFactory.getDatabaseSchema();
		diffs = new SchemaDifferences();
		xmlSchema.computeDifferencesFromActual(diffs, sqlSchema);
		assertEquals(0, diffs.getSize());
		
	}	
	
	public void verifyData(Data data, String expected, Connection conn) throws Exception {
		Statement stmt = conn.createStatement();
		String sql = "select data from jdbc_manager_test_a where id = " + data.id;
		ResultSet rs = stmt.executeQuery(sql);
		if (rs.next()){
			String dataStr = rs.getString("data");
			assertEquals(expected, dataStr);
		}
	}
	
	
	public void insertData(Data data, Connection conn) throws SQLException {
		PreparedStatement stmt = null;
		String sql = "insert into jdbc_manager_test_a (id, data, name) values (?,?,?)";
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setInt(1, data.id);
			stmt.setBytes(2, data.data);
			stmt.setString(3, data.name);
			/*int i = */stmt.executeUpdate();
			
		} finally {
			if (stmt != null){
				stmt.close();
			}
		}
		
	}
	
	public class Data {
		public int id; 
		public byte[] data;
		public String name;
	}
		
}
